﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace MU2DLIB.Input
{
    public sealed class MouseManager
    {
        #region Declaration

        private const int INPUTDELAY = 50;

        private MouseState m_MouseState;

        private static MouseManager m_Instance = null;

        private bool m_IsMouseVisible;

        #endregion

        #region Constructor

        private MouseManager()
        {
            this.m_IsMouseVisible = true;
        }

        #endregion

        #region Properties

        public int Delay
        {
            get { return INPUTDELAY; }
        }

        public bool IsMouseVisible
        {
            get { return this.m_IsMouseVisible; }
            set { this.m_IsMouseVisible = value; }
        }

        #endregion

        #region Methods

        public static MouseManager GetInstance()
        {
            if (m_Instance == null)
                m_Instance = new MouseManager();

            return m_Instance;
        }

        public Point MousePositionPoint()
        {
            return new Point(this.m_MouseState.X, this.m_MouseState.Y);
        }

        public Vector2 MousePositionVector2()
        {
            return new Vector2(this.m_MouseState.X, this.m_MouseState.Y);
        }

        public bool LeftButtonPressed()
        {
            if (this.m_MouseState.LeftButton == ButtonState.Pressed)
                return true;

            return false;
        }

        public bool RightButtonPressed()
        {
            if (this.m_MouseState.RightButton == ButtonState.Pressed)
                return true;

            return false;
        }

        public bool LeftButtonReleased()
        {
            if (this.m_MouseState.LeftButton == ButtonState.Released)
                return true;

            return false;
        }

        public bool RightButtonReleased()
        {
            if (this.m_MouseState.RightButton == ButtonState.Released)
                return true;

            return false;
        }

        public bool MiddleButtonPressed()
        {
            if (this.m_MouseState.MiddleButton == ButtonState.Pressed)
                return true;

            return false;
        }

        public bool MiddleButtonReleased()
        {
            if (this.m_MouseState.MiddleButton == ButtonState.Released)
                return true;

            return false;
        }

        public int WheelValue()
        {
            return this.m_MouseState.ScrollWheelValue;
        }

        public void Update(GameTime gameTime)
        {
            this.m_MouseState = Mouse.GetState();
        }

        #endregion
    }
}
